package org.huangxiaozhe.adventure;

import org.huangxiaozhe.adventure.common.ConstantUtil;

import com.triplefstudio.adventure.R;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;

public class Tools {

	GameView gameView;
	Bitmap bitmap0, bitmap1, bitmap2, bitmap3, bitmap4;
	Paint paint = new Paint(Color.BLACK);
	
	public Tools(GameView gameView){
		this.gameView = gameView;
		initResource();
	}
	private void initResource() {
		bitmap0 = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.bt0);
		bitmap1 = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.bt1);
		bitmap2 = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.bt2);
		bitmap3 = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.bt3);
		bitmap4 = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.bt4);
		ConstantUtil.toolCount = 5;
		ConstantUtil.toolWidth = bitmap1.getWidth();
	}
	
	public void draw(Canvas canvas){
		int x = ConstantUtil.toolX;
		canvas.drawBitmap(bitmap0, x, ConstantUtil.toolY, paint);
		x += ConstantUtil.toolWidth + ConstantUtil.toolLength;
		canvas.drawBitmap(bitmap1, x, ConstantUtil.toolY, paint);
		x += ConstantUtil.toolWidth + ConstantUtil.toolLength;
		canvas.drawBitmap(bitmap2, x, ConstantUtil.toolY, paint);
		x += ConstantUtil.toolWidth + ConstantUtil.toolLength;
		canvas.drawBitmap(bitmap3, x, ConstantUtil.toolY, paint);
		x += ConstantUtil.toolWidth + ConstantUtil.toolLength;
		canvas.drawBitmap(bitmap4, x, ConstantUtil.toolY, paint);
	}
	
	//��ݺ������ȡ�õ�ǰ���ߵ�����ֵ
	public int isInclude(float px, float py){
		if(py >= ConstantUtil.toolY && py <= ConstantUtil.toolY + ConstantUtil.toolWidth){
			if(px >= ConstantUtil.toolX - ConstantUtil.toolLength/2 &&
					px <= ConstantUtil.toolX + ConstantUtil.toolCount * (ConstantUtil.toolLength + ConstantUtil.toolWidth) - ConstantUtil.toolLength/2){
				return   (int) ((px - ConstantUtil.toolX + ConstantUtil.toolLength/2)/(ConstantUtil.toolWidth + ConstantUtil.toolLength));
			}
		}
		return -1;
	}
}
